<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"></meta>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"></meta>
<title>添加</title>
<span th:replace="common-easyui-mobile::easyui_mobile_js_css"></span>

<script th:inline="javascript">
	//<![CDATA[
	function submitForm(){
	  if($("#addForm").form('validate')){
		$.ajax({
	         type: "POST",
	         url:ctx+'/stock/save',
	         data: $('#addForm').serialize(),
	         success: function (data) {
	        	location.href=ctx+"/list";
	         },
	         error: function(data) {
	             alert("error:"+data.responseText);
	          }
	   		});
	   }
	};
	
	//根据Code设置名称
	function setNameByCode(){
		var code=$('#code').textbox('getValue');
		$.ajax({
	         type: "POST",
	         url:ctx+'/stock/getStockInfoFromWsByCode',
	         data: {
	        	 code:code
	         },
	         success: function (data) {
	        	 if(data.name=='ERROR'){
	        		 $.messager.alert('错误',"您输入的代码有误，请重新输入！");
	        		 $('#code').textbox('setValue','');
	        	 }else{
	        		$('#name').textbox('setValue',data.name);
	 	        	$('#currentPrice').textbox('setValue',data.currentPrice);
	        	 }
	        	
	         },
	         error: function(data) {
	             alert("error:"+data.responseText);
	          }
	   		});
	   }
		
	
	
//]]>
</script>

</head>
<body>
 <div class="easyui-navpanel" style="position:relative;padding:20px">
        <header>
            <div class="m-toolbar">
                <div class="m-title">新增</div>
                <div class="m-left">
                     <a th:href="@{/list}" class="easyui-linkbutton m-back" plain="true" outline="true">返回</a>
                </div>
                <div class="m-right">
                     <a href="javascript:void(0)"  onclick="submitForm()" class="easyui-linkbutton m-next c4" plain="true" outline="true">提交</a>
                </div>
            </div>
        </header>
        <form id="addForm">
            <div style="margin-bottom:10px">
                <input class="easyui-textbox" id="code" name="code"  label="代码:" prompt="代码,上证前加sh,如sh600318,深证前加sz,如sz002230" data-options="required:true,onChange:function(){setNameByCode()}" style="width:100%" />
            </div>
            <div style="margin-bottom:10px">
                <input class="easyui-textbox" id="name" name="name" label="名称:" prompt="名称" data-options="required:true,readonly:true" style="width:100%" />
            </div>
             <div style="margin-bottom:10px">
                <input class="easyui-textbox" id="currentPrice" label="当前价" prompt="当前价" data-options="required:true,readonly:true" style="width:100%" />
            </div>
            
            <div style="margin-bottom:10px">
                <input class="easyui-textbox" name="buyPrice" label="成本价:" prompt="成本价" data-options="required:true,validType:'currency'" style="width:100%" />
            </div>
            
            <div style="margin-bottom:10px">
                <input class="easyui-numberbox" name="buyCount" label="数量" prompt="数量" style="width:100%" />
            </div>
            
            
           
        </form>
    </div>
</body>
</html>